
#ifndef STYLEEDIT_H
#define STYLEEDIT_H

#include <BMap>
#include <BFont>
#include <BImage>
#include <BTextEdit>

using namespace BWE;

class StyleFormat : public BTextFormat
{
public:
	struct Node
	{
		BFontHolder		font;
		BColor			color;
		int				end;
	};

	virtual const BFont* font(int pos) const
	{
		auto cit = _nodeMap.lessEqual(pos);
		if (cit.valid() && pos < cit->end)
			return cit->font;
		return 0;
	}
	virtual const BColor* color(int pos) const
	{
		auto cit = _nodeMap.lessEqual(pos);
		if (cit.valid() && pos < cit->end)
			return &cit->color;
		return 0;
	}

	Node& insert(int pos, int end)
	{
		auto it = _nodeMap.insert(pos);
		it->end = end;
		return *it;
	}
	void reset()
	{
		_nodeMap.reset();
	}

private:
	BMap<int, Node>		_nodeMap;
};

class StyleEdit : public BTextEdit
{
	BOBJECT(StyleEdit)
public:
	StyleEdit(BWidget* parent = 0);
	~StyleEdit();

	void setFileName(const BString& fileName);
	const BString& fileName() const;

	bool load();
	bool save() const;

protected:
	void syntax();

protected:
	void slotTextChanged();
	void slotTextEdited();

protected:
	virtual void styleEvent(const BEvent& event);

private:
	BString			_fileName;
	BFontHolder		_nameFont;
	BFontHolder		_signFont;
	BFontHolder		_noteFont;
};

#endif